using DataDynamics.ActiveReports;
using DataDynamics.ActiveReports.Export.Xls;
using SM.core;
using SS;
using System;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Windows.Forms;
using TVSBH.core;
namespace TVSBH.func
{
	public class frmDebtNeedIn : Form
	{
		private IContainer components = null;
		private GroupBox groupBox1;
		private System.Windows.Forms.CheckBox ckbProviderAll;
		private ComboBox cbbProvider;
		private System.Windows.Forms.Label label1;
		private DataGridView dgvProduct;
		private Button btnPrint;
		private Button btnClose;
		private System.Windows.Forms.TextBox txtAllMoney;
		private DataGridView dgvBill;
		private Button btnReport;
		private DataGridViewTextBoxColumn Column7;
		private DataGridViewTextBoxColumn Column2;
		private DataGridViewTextBoxColumn Column5;
		private DataGridViewTextBoxColumn Column3;
		private DataGridViewTextBoxColumn cusID;
		private DataGridViewTextBoxColumn dataGridViewTextBoxColumn1;
		private DataGridViewTextBoxColumn dataGridViewTextBoxColumn7;
		private DataGridViewTextBoxColumn Column10;
		private DataGridViewTextBoxColumn Column11;
		private DataGridViewTextBoxColumn Column12;
		private DataGridViewTextBoxColumn Column13;
		private DataGridViewTextBoxColumn Column14;
		private DataGridViewTextBoxColumn Note;
		private DataGridViewTextBoxColumn TotalMoney;
		private System.Windows.Forms.Label label2;
		private GroupBox groupBox2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label lblObjectName;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Label lblDebt;
		private System.Windows.Forms.Label lblPayed;
		private System.Windows.Forms.Label lblTotalDebt;
		private System.Windows.Forms.Label label7;
		private Button btnExportToExcel;
		private Button btnExportToExcel1;
		private Func objFunc = new Func();
		private DataTable objTable = new DataTable();
		private Bill objBill = new Bill();
		private Partner objPartner = new Partner();
		private string currPid = "";
		private string currAddress = "";
		private string currPhone = "";
		private DataTable objDetailTable;
		protected override void Dispose(bool disposing)
		{
			if (disposing && this.components != null)
			{
				this.components.Dispose();
			}
			base.Dispose(disposing);
		}
		private void InitializeComponent()
		{
			DataGridViewCellStyle dataGridViewCellStyle = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle2 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle3 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle4 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle5 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle6 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle7 = new DataGridViewCellStyle();
			ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof(frmDebtNeedIn));
			this.groupBox1 = new GroupBox();
			this.label1 = new System.Windows.Forms.Label();
			this.ckbProviderAll = new System.Windows.Forms.CheckBox();
			this.cbbProvider = new ComboBox();
			this.dgvProduct = new DataGridView();
			this.Column7 = new DataGridViewTextBoxColumn();
			this.Column2 = new DataGridViewTextBoxColumn();
			this.Column5 = new DataGridViewTextBoxColumn();
			this.Column3 = new DataGridViewTextBoxColumn();
			this.cusID = new DataGridViewTextBoxColumn();
			this.btnPrint = new Button();
			this.btnClose = new Button();
			this.txtAllMoney = new System.Windows.Forms.TextBox();
			this.dgvBill = new DataGridView();
			this.dataGridViewTextBoxColumn1 = new DataGridViewTextBoxColumn();
			this.dataGridViewTextBoxColumn7 = new DataGridViewTextBoxColumn();
			this.Column10 = new DataGridViewTextBoxColumn();
			this.Column11 = new DataGridViewTextBoxColumn();
			this.Column12 = new DataGridViewTextBoxColumn();
			this.Column13 = new DataGridViewTextBoxColumn();
			this.Column14 = new DataGridViewTextBoxColumn();
			this.Note = new DataGridViewTextBoxColumn();
			this.TotalMoney = new DataGridViewTextBoxColumn();
			this.btnReport = new Button();
			this.label2 = new System.Windows.Forms.Label();
			this.groupBox2 = new GroupBox();
			this.lblTotalDebt = new System.Windows.Forms.Label();
			this.label7 = new System.Windows.Forms.Label();
			this.lblPayed = new System.Windows.Forms.Label();
			this.lblDebt = new System.Windows.Forms.Label();
			this.label5 = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.lblObjectName = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.btnExportToExcel = new Button();
			this.btnExportToExcel1 = new Button();
			this.groupBox1.SuspendLayout();
			((ISupportInitialize)this.dgvProduct).BeginInit();
			((ISupportInitialize)this.dgvBill).BeginInit();
			this.groupBox2.SuspendLayout();
			base.SuspendLayout();
			this.groupBox1.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.groupBox1.BackColor = Color.White;
			this.groupBox1.Controls.Add(this.label1);
			this.groupBox1.Controls.Add(this.ckbProviderAll);
			this.groupBox1.Controls.Add(this.cbbProvider);
			this.groupBox1.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.groupBox1.Location = new System.Drawing.Point(7, 2);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new Size(887, 51);
			this.groupBox1.TabIndex = 1;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Thông tin tìm kiếm";
			this.label1.AutoSize = true;
			this.label1.Font = new Font("Arial", 9f);
			this.label1.Location = new System.Drawing.Point(119, 21);
			this.label1.Name = "label1";
			this.label1.Size = new Size(99, 15);
			this.label1.TabIndex = 62;
			this.label1.Text = "Chọn đối tượng :";
			this.ckbProviderAll.AutoSize = true;
			this.ckbProviderAll.Checked = true;
			this.ckbProviderAll.CheckState = CheckState.Checked;
			this.ckbProviderAll.Font = new Font("Arial", 9f);
			this.ckbProviderAll.Location = new System.Drawing.Point(625, 20);
			this.ckbProviderAll.Name = "ckbProviderAll";
			this.ckbProviderAll.Size = new Size(83, 19);
			this.ckbProviderAll.TabIndex = 61;
			this.ckbProviderAll.Text = "Xem tất cả";
			this.ckbProviderAll.UseVisualStyleBackColor = true;
			this.ckbProviderAll.CheckedChanged += new EventHandler(this.ckbProviderAll_CheckedChanged);
			this.cbbProvider.BackColor = Color.White;
			this.cbbProvider.DropDownStyle = ComboBoxStyle.DropDownList;
			this.cbbProvider.FlatStyle = FlatStyle.Flat;
			this.cbbProvider.Font = new Font("Arial", 8.5f);
			this.cbbProvider.FormattingEnabled = true;
			this.cbbProvider.Location = new System.Drawing.Point(222, 17);
			this.cbbProvider.Name = "cbbProvider";
			this.cbbProvider.Size = new Size(396, 22);
			this.cbbProvider.TabIndex = 56;
			this.cbbProvider.SelectedIndexChanged += new EventHandler(this.cbbProvider_SelectedIndexChanged);
			this.dgvProduct.AllowUserToAddRows = false;
			this.dgvProduct.AllowUserToDeleteRows = false;
			this.dgvProduct.AllowUserToOrderColumns = true;
			this.dgvProduct.AllowUserToResizeColumns = false;
			this.dgvProduct.AllowUserToResizeRows = false;
			dataGridViewCellStyle.BackColor = Color.FromArgb(192, 255, 255);
			dataGridViewCellStyle.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvProduct.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle;
			this.dgvProduct.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.dgvProduct.BackgroundColor = Color.White;
			this.dgvProduct.BorderStyle = BorderStyle.Fixed3D;
			this.dgvProduct.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
			this.dgvProduct.Columns.AddRange(new DataGridViewColumn[]
			{
				this.Column7,
				this.Column2,
				this.Column5,
				this.Column3,
				this.cusID
			});
			this.dgvProduct.Cursor = Cursors.Hand;
			this.dgvProduct.EnableHeadersVisualStyles = false;
			this.dgvProduct.Location = new System.Drawing.Point(7, 59);
			this.dgvProduct.MultiSelect = false;
			this.dgvProduct.Name = "dgvProduct";
			this.dgvProduct.ReadOnly = true;
			this.dgvProduct.RowHeadersVisible = false;
			this.dgvProduct.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;
			dataGridViewCellStyle2.BackColor = Color.White;
			dataGridViewCellStyle2.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvProduct.RowsDefaultCellStyle = dataGridViewCellStyle2;
			this.dgvProduct.RowTemplate.DefaultCellStyle.BackColor = Color.White;
			this.dgvProduct.RowTemplate.DefaultCellStyle.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvProduct.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
			this.dgvProduct.Size = new Size(886, 267);
			this.dgvProduct.TabIndex = 3;
			this.dgvProduct.CellClick += new DataGridViewCellEventHandler(this.dgvProduct_CellClick);
			this.dgvProduct.CellEnter += new DataGridViewCellEventHandler(this.dgvProduct_CellEnter);
			this.Column7.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.Column7.DataPropertyName = "Name";
			dataGridViewCellStyle3.Format = "D";
			dataGridViewCellStyle3.NullValue = null;
			this.Column7.DefaultCellStyle = dataGridViewCellStyle3;
			this.Column7.HeaderText = "Đối tượng";
			this.Column7.MinimumWidth = 400;
			this.Column7.Name = "Column7";
			this.Column7.ReadOnly = true;
			this.Column7.Width = 400;
			this.Column2.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
			this.Column2.DataPropertyName = "Address";
			this.Column2.HeaderText = "Địa chỉ";
			this.Column2.MinimumWidth = 200;
			this.Column2.Name = "Column2";
			this.Column2.ReadOnly = true;
			this.Column5.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.Column5.DataPropertyName = "Phone";
			this.Column5.HeaderText = "Điện thoại";
			this.Column5.MinimumWidth = 120;
			this.Column5.Name = "Column5";
			this.Column5.ReadOnly = true;
			this.Column5.Width = 120;
			this.Column3.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.Column3.DataPropertyName = "Money";
			dataGridViewCellStyle4.Alignment = DataGridViewContentAlignment.MiddleRight;
			dataGridViewCellStyle4.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			dataGridViewCellStyle4.ForeColor = Color.Red;
			this.Column3.DefaultCellStyle = dataGridViewCellStyle4;
			this.Column3.HeaderText = "Công nợ";
			this.Column3.MinimumWidth = 120;
			this.Column3.Name = "Column3";
			this.Column3.ReadOnly = true;
			this.Column3.Width = 120;
			this.cusID.DataPropertyName = "CusID";
			this.cusID.HeaderText = "CusID";
			this.cusID.Name = "cusID";
			this.cusID.ReadOnly = true;
			this.cusID.Visible = false;
			this.btnPrint.Enabled = false;
			this.btnPrint.FlatAppearance.BorderColor = Color.FromArgb(255, 128, 255);
			this.btnPrint.FlatStyle = FlatStyle.Flat;
			this.btnPrint.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnPrint.Location = new System.Drawing.Point(7, 330);
			this.btnPrint.Name = "btnPrint";
			this.btnPrint.Size = new Size(102, 26);
			this.btnPrint.TabIndex = 45;
			this.btnPrint.Text = "Xem và in [ F7 ]";
			this.btnPrint.UseVisualStyleBackColor = true;
			this.btnPrint.Click += new EventHandler(this.btnPrint_Click);
			this.btnClose.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right);
			this.btnClose.FlatAppearance.BorderColor = Color.FromArgb(255, 128, 255);
			this.btnClose.FlatStyle = FlatStyle.Flat;
			this.btnClose.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnClose.Location = new System.Drawing.Point(794, 568);
			this.btnClose.Name = "btnClose";
			this.btnClose.Size = new Size(100, 26);
			this.btnClose.TabIndex = 44;
			this.btnClose.Text = "Thoát  [ ESC ]";
			this.btnClose.UseVisualStyleBackColor = true;
			this.btnClose.Click += new EventHandler(this.btnClose_Click);
			this.txtAllMoney.Anchor = (AnchorStyles.Top | AnchorStyles.Right);
			this.txtAllMoney.BackColor = Color.White;
			this.txtAllMoney.Font = new Font("Arial", 9.75f, FontStyle.Bold, GraphicsUnit.Point, 0);
			this.txtAllMoney.ForeColor = Color.Red;
			this.txtAllMoney.Location = new System.Drawing.Point(784, 334);
			this.txtAllMoney.Name = "txtAllMoney";
			this.txtAllMoney.ReadOnly = true;
			this.txtAllMoney.Size = new Size(109, 22);
			this.txtAllMoney.TabIndex = 46;
			this.txtAllMoney.TextAlign = HorizontalAlignment.Right;
			this.dgvBill.AllowUserToAddRows = false;
			this.dgvBill.AllowUserToDeleteRows = false;
			this.dgvBill.AllowUserToOrderColumns = true;
			this.dgvBill.AllowUserToResizeColumns = false;
			this.dgvBill.AllowUserToResizeRows = false;
			dataGridViewCellStyle5.BackColor = Color.FromArgb(192, 255, 255);
			dataGridViewCellStyle5.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvBill.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle5;
			this.dgvBill.Anchor = (AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right);
			this.dgvBill.BackgroundColor = Color.White;
			this.dgvBill.BorderStyle = BorderStyle.Fixed3D;
			this.dgvBill.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
			this.dgvBill.Columns.AddRange(new DataGridViewColumn[]
			{
				this.dataGridViewTextBoxColumn1,
				this.dataGridViewTextBoxColumn7,
				this.Column10,
				this.Column11,
				this.Column12,
				this.Column13,
				this.Column14,
				this.Note,
				this.TotalMoney
			});
			this.dgvBill.Cursor = Cursors.Hand;
			this.dgvBill.EnableHeadersVisualStyles = false;
			this.dgvBill.Location = new System.Drawing.Point(7, 421);
			this.dgvBill.MultiSelect = false;
			this.dgvBill.Name = "dgvBill";
			this.dgvBill.ReadOnly = true;
			this.dgvBill.RowHeadersVisible = false;
			this.dgvBill.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;
			this.dgvBill.RowTemplate.DefaultCellStyle.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvBill.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
			this.dgvBill.Size = new Size(887, 141);
			this.dgvBill.TabIndex = 47;
			this.dataGridViewTextBoxColumn1.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.dataGridViewTextBoxColumn1.DataPropertyName = "ID";
			this.dataGridViewTextBoxColumn1.HeaderText = "Hoá đơn";
			this.dataGridViewTextBoxColumn1.MinimumWidth = 160;
			this.dataGridViewTextBoxColumn1.Name = "dataGridViewTextBoxColumn1";
			this.dataGridViewTextBoxColumn1.ReadOnly = true;
			this.dataGridViewTextBoxColumn1.Width = 160;
			this.dataGridViewTextBoxColumn7.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.dataGridViewTextBoxColumn7.DataPropertyName = "CreateDate";
			dataGridViewCellStyle6.Format = "D";
			dataGridViewCellStyle6.NullValue = null;
			this.dataGridViewTextBoxColumn7.DefaultCellStyle = dataGridViewCellStyle6;
			this.dataGridViewTextBoxColumn7.HeaderText = "Ngày lập";
			this.dataGridViewTextBoxColumn7.MinimumWidth = 120;
			this.dataGridViewTextBoxColumn7.Name = "dataGridViewTextBoxColumn7";
			this.dataGridViewTextBoxColumn7.ReadOnly = true;
			this.dataGridViewTextBoxColumn7.Width = 120;
			this.Column10.DataPropertyName = "TotalMoney";
			this.Column10.HeaderText = "TotalMoney";
			this.Column10.Name = "Column10";
			this.Column10.ReadOnly = true;
			this.Column10.Visible = false;
			this.Column11.DataPropertyName = "TypeInput";
			this.Column11.HeaderText = "TypeInput";
			this.Column11.Name = "Column11";
			this.Column11.ReadOnly = true;
			this.Column11.Visible = false;
			this.Column12.DataPropertyName = "WID";
			this.Column12.HeaderText = "WID";
			this.Column12.Name = "Column12";
			this.Column12.ReadOnly = true;
			this.Column12.Visible = false;
			this.Column13.DataPropertyName = "Note";
			this.Column13.HeaderText = "Note";
			this.Column13.Name = "Column13";
			this.Column13.ReadOnly = true;
			this.Column13.Visible = false;
			this.Column14.DataPropertyName = "PID";
			this.Column14.HeaderText = "PID";
			this.Column14.Name = "Column14";
			this.Column14.ReadOnly = true;
			this.Column14.Visible = false;
			this.Note.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
			this.Note.DataPropertyName = "Note";
			this.Note.HeaderText = "Diễn giải";
			this.Note.MinimumWidth = 250;
			this.Note.Name = "Note";
			this.Note.ReadOnly = true;
			this.TotalMoney.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.TotalMoney.DataPropertyName = "TotalMoney";
			dataGridViewCellStyle7.Alignment = DataGridViewContentAlignment.MiddleRight;
			dataGridViewCellStyle7.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.TotalMoney.DefaultCellStyle = dataGridViewCellStyle7;
			this.TotalMoney.HeaderText = "Tổng tiền";
			this.TotalMoney.MinimumWidth = 120;
			this.TotalMoney.Name = "TotalMoney";
			this.TotalMoney.ReadOnly = true;
			this.TotalMoney.Width = 120;
			this.btnReport.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left);
			this.btnReport.Enabled = false;
			this.btnReport.FlatAppearance.BorderColor = Color.FromArgb(255, 128, 255);
			this.btnReport.FlatStyle = FlatStyle.Flat;
			this.btnReport.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnReport.Location = new System.Drawing.Point(7, 568);
			this.btnReport.Name = "btnReport";
			this.btnReport.Size = new Size(84, 26);
			this.btnReport.TabIndex = 48;
			this.btnReport.Text = "In báo cáo";
			this.btnReport.UseVisualStyleBackColor = true;
			this.btnReport.Click += new EventHandler(this.btnReport_Click);
			this.label2.Anchor = (AnchorStyles.Top | AnchorStyles.Right);
			this.label2.AutoSize = true;
			this.label2.Location = new System.Drawing.Point(645, 337);
			this.label2.Name = "label2";
			this.label2.Size = new Size(136, 15);
			this.label2.TabIndex = 51;
			this.label2.Text = "Tổng công nợ phải thu :";
			this.groupBox2.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.groupBox2.Controls.Add(this.lblTotalDebt);
			this.groupBox2.Controls.Add(this.label7);
			this.groupBox2.Controls.Add(this.lblPayed);
			this.groupBox2.Controls.Add(this.lblDebt);
			this.groupBox2.Controls.Add(this.label5);
			this.groupBox2.Controls.Add(this.label4);
			this.groupBox2.Controls.Add(this.lblObjectName);
			this.groupBox2.Controls.Add(this.label3);
			this.groupBox2.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.groupBox2.Location = new System.Drawing.Point(7, 361);
			this.groupBox2.Name = "groupBox2";
			this.groupBox2.Size = new Size(886, 54);
			this.groupBox2.TabIndex = 52;
			this.groupBox2.TabStop = false;
			this.groupBox2.Text = "Đối tượng được chọn";
			this.lblTotalDebt.Anchor = (AnchorStyles.Top | AnchorStyles.Right);
			this.lblTotalDebt.BackColor = Color.White;
			this.lblTotalDebt.BorderStyle = BorderStyle.Fixed3D;
			this.lblTotalDebt.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.lblTotalDebt.Location = new System.Drawing.Point(454, 20);
			this.lblTotalDebt.Name = "lblTotalDebt";
			this.lblTotalDebt.Size = new Size(103, 23);
			this.lblTotalDebt.TabIndex = 7;
			this.lblTotalDebt.TextAlign = ContentAlignment.MiddleRight;
			this.label7.Anchor = (AnchorStyles.Top | AnchorStyles.Right);
			this.label7.AutoSize = true;
			this.label7.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.label7.Location = new System.Drawing.Point(391, 24);
			this.label7.Name = "label7";
			this.label7.Size = new Size(59, 15);
			this.label7.TabIndex = 6;
			this.label7.Text = "Tổng nợ :";
			this.lblPayed.Anchor = (AnchorStyles.Top | AnchorStyles.Right);
			this.lblPayed.BackColor = Color.White;
			this.lblPayed.BorderStyle = BorderStyle.Fixed3D;
			this.lblPayed.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.lblPayed.Location = new System.Drawing.Point(612, 20);
			this.lblPayed.Name = "lblPayed";
			this.lblPayed.Size = new Size(103, 23);
			this.lblPayed.TabIndex = 5;
			this.lblPayed.TextAlign = ContentAlignment.MiddleRight;
			this.lblDebt.Anchor = (AnchorStyles.Top | AnchorStyles.Right);
			this.lblDebt.BackColor = Color.White;
			this.lblDebt.BorderStyle = BorderStyle.Fixed3D;
			this.lblDebt.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.lblDebt.Location = new System.Drawing.Point(778, 19);
			this.lblDebt.Name = "lblDebt";
			this.lblDebt.Size = new Size(103, 23);
			this.lblDebt.TabIndex = 4;
			this.lblDebt.TextAlign = ContentAlignment.MiddleRight;
			this.label5.Anchor = (AnchorStyles.Top | AnchorStyles.Right);
			this.label5.AutoSize = true;
			this.label5.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.label5.Location = new System.Drawing.Point(720, 23);
			this.label5.Name = "label5";
			this.label5.Size = new Size(54, 15);
			this.label5.TabIndex = 3;
			this.label5.Text = "Còn nợ :";
			this.label4.Anchor = (AnchorStyles.Top | AnchorStyles.Right);
			this.label4.AutoSize = true;
			this.label4.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.label4.Location = new System.Drawing.Point(562, 24);
			this.label4.Name = "label4";
			this.label4.Size = new Size(46, 15);
			this.label4.TabIndex = 2;
			this.label4.Text = "Đã trả :";
			this.lblObjectName.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.lblObjectName.BackColor = Color.White;
			this.lblObjectName.BorderStyle = BorderStyle.Fixed3D;
			this.lblObjectName.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.lblObjectName.Location = new System.Drawing.Point(129, 20);
			this.lblObjectName.Name = "lblObjectName";
			this.lblObjectName.Size = new Size(257, 23);
			this.lblObjectName.TabIndex = 1;
			this.lblObjectName.TextAlign = ContentAlignment.MiddleLeft;
			this.label3.AutoSize = true;
			this.label3.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.label3.Location = new System.Drawing.Point(57, 24);
			this.label3.Name = "label3";
			this.label3.Size = new Size(68, 15);
			this.label3.TabIndex = 0;
			this.label3.Text = "Đối tượng :";
			this.btnExportToExcel.Enabled = false;
			this.btnExportToExcel.FlatAppearance.BorderColor = Color.FromArgb(255, 128, 255);
			this.btnExportToExcel.FlatStyle = FlatStyle.Flat;
			this.btnExportToExcel.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnExportToExcel.Location = new System.Drawing.Point(110, 330);
			this.btnExportToExcel.Name = "btnExportToExcel";
			this.btnExportToExcel.Size = new Size(80, 26);
			this.btnExportToExcel.TabIndex = 53;
			this.btnExportToExcel.Text = "Xuất Excel";
			this.btnExportToExcel.UseVisualStyleBackColor = true;
			this.btnExportToExcel.Click += new EventHandler(this.btnExportToExcel_Click);
			this.btnExportToExcel1.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left);
			this.btnExportToExcel1.Enabled = false;
			this.btnExportToExcel1.FlatAppearance.BorderColor = Color.FromArgb(255, 128, 255);
			this.btnExportToExcel1.FlatStyle = FlatStyle.Flat;
			this.btnExportToExcel1.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnExportToExcel1.Location = new System.Drawing.Point(94, 568);
			this.btnExportToExcel1.Name = "btnExportToExcel1";
			this.btnExportToExcel1.Size = new Size(102, 26);
			this.btnExportToExcel1.TabIndex = 54;
			this.btnExportToExcel1.Text = "Xuất file Excel";
			this.btnExportToExcel1.UseVisualStyleBackColor = true;
			this.btnExportToExcel1.Click += new EventHandler(this.btnExportToExcel1_Click);
			base.AutoScaleDimensions = new SizeF(7f, 15f);
			//base.AutoScaleMode = AutoScaleMode.Font;
			this.BackColor = Color.White;
			base.ClientSize = new Size(900, 600);
			base.Controls.Add(this.btnExportToExcel1);
			base.Controls.Add(this.btnExportToExcel);
			base.Controls.Add(this.label2);
			base.Controls.Add(this.btnReport);
			base.Controls.Add(this.dgvBill);
			base.Controls.Add(this.txtAllMoney);
			base.Controls.Add(this.btnPrint);
			base.Controls.Add(this.btnClose);
			base.Controls.Add(this.dgvProduct);
			base.Controls.Add(this.groupBox1);
			base.Controls.Add(this.groupBox2);
			this.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 0);
			//base.Icon = (System.Drawing.Icon)componentResourceManager.GetObject("$this.Icon");
			//base.Icon = (Icon)componentResourceManager.GetObject("$this.Icon");
			base.KeyPreview = true;
			base.Name = "frmDebtNeedIn";
			base.ShowInTaskbar = false;
			base.StartPosition = FormStartPosition.CenterScreen;
			this.Text = "CÔNG NỢ CẦN THU";
			base.WindowState = FormWindowState.Maximized;
			base.Load += new EventHandler(this.frmDebtNeedIn_Load);
			base.KeyDown += new KeyEventHandler(this.frmDebtNeedIn_KeyDown);
			this.groupBox1.ResumeLayout(false);
			this.groupBox1.PerformLayout();
			((ISupportInitialize)this.dgvProduct).EndInit();
			((ISupportInitialize)this.dgvBill).EndInit();
			this.groupBox2.ResumeLayout(false);
			this.groupBox2.PerformLayout();
			base.ResumeLayout(false);
			base.PerformLayout();
		}
		public frmDebtNeedIn()
		{
			this.InitializeComponent();
		}
		private void frmDebtNeedIn_Load(object sender, EventArgs e)
		{
			Program.strConnectionString = this.objFunc.strConnectionString;
			this.objFunc.LoadComboBox("SELECT CusID, UPPER(Name) AS NAME FROM [TabPartner] WHERE [CusID] <> '' ORDER BY Name", this.cbbProvider, "CusID", "Name");
			if (this.ckbProviderAll.Checked)
			{
				this.getData();
			}
		}
		private void getData()
		{
			if (this.cbbProvider.Items.Count > 0)
			{
				DataTable dataTable = new DataTable();
				DataColumn column = new DataColumn("Name", typeof(string));
				DataColumn column2 = new DataColumn("Address", typeof(string));
				DataColumn column3 = new DataColumn("Phone", typeof(string));
				DataColumn column4 = new DataColumn("Money", typeof(string));
				DataColumn column5 = new DataColumn("CusID", typeof(string));
				dataTable.Columns.Add(column);
				dataTable.Columns.Add(column2);
				dataTable.Columns.Add(column3);
				dataTable.Columns.Add(column4);
				dataTable.Columns.Add(column5);
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = sqlConnection.CreateCommand();
				if (this.ckbProviderAll.Checked)
				{
					sqlCommand.CommandText = "SELECT * FROM [TabPartner] WHERE [IsCustomer] = 1 ORDER BY [Name]";
				}
				else
				{
					sqlCommand.CommandText = "SELECT * FROM [TabPartner] WHERE [CusID] = '" + this.cbbProvider.SelectedValue.ToString() + "' ORDER BY [Name]";
				}
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				double num = 0.0;
				while (sqlDataReader.Read())
				{
					double num2 = this.objPartner.getFistBalanceCustomer(sqlDataReader["CusID"].ToString()) + this.objPartner.getTotalMoney(sqlDataReader["CusID"].ToString()) - this.objPartner.getTotalMoneyPayedCustomer(sqlDataReader["CusID"].ToString());
					num += num2;
					dataTable.Rows.Add(new object[]
					{
						sqlDataReader["Name"].ToString().ToUpper(),
						sqlDataReader["Address"].ToString(),
						sqlDataReader["Phone"].ToString(),
						string.Format(Program.lenAffterDecimal, num2),
						sqlDataReader["CusID"].ToString()
					});
				}
				sqlDataReader.Close();
				sqlConnection.Close();
				sqlConnection.Dispose();
				this.btnPrint.Enabled = true;
				this.objTable = dataTable;
				this.dgvProduct.DataSource = this.objTable;
				this.txtAllMoney.Text = string.Format(Program.lenAffterDecimal, num);
				if (this.dgvProduct.Rows.Count > 0)
				{
					this.btnPrint.Enabled = true;
					this.btnExportToExcel.Enabled = true;
				}
				else
				{
					this.btnPrint.Enabled = false;
					this.btnExportToExcel.Enabled = false;
				}
			}
			else
			{
				MessageBox.Show("Không có đối tượng nào tồn tại trên hệ thống\r\n\r\nCông tác quản lý không thể thực hiện được", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
			}
		}
		private void btnClose_Click(object sender, EventArgs e)
		{
			base.Close();
		}
		private void frmDebtNeedIn_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Escape)
			{
				base.Close();
			}
			else
			{
				if (e.KeyCode == Keys.F7)
				{
					this.btnPrint.PerformClick();
				}
			}
		}
		private void ckbProviderAll_CheckedChanged(object sender, EventArgs e)
		{
			this.getData();
		}
		private void cbbProvider_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (!this.ckbProviderAll.Checked)
			{
				this.getData();
			}
		}
		private void btnPrint_Click(object sender, EventArgs e)
		{
			frmRepDebtNeedIn.objTable = new DataTable();
			frmDebtNeedInView frmDebtNeedInView = new frmDebtNeedInView();
			frmRepDebtNeedIn.objTable = this.objTable;
			frmDebtNeedInView.totalMoney = this.txtAllMoney.Text;
			frmDebtNeedInView.ShowDialog();
			try
			{
				this.dgvProduct.Columns["TT"].Visible = false;
			}
			catch
			{
			}
		}
		private void getBillInput()
		{
			this.objDetailTable = new DataTable();
			this.dgvBill.AutoGenerateColumns = false;
			SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
			string cmdText = "SELECT * FROM [TabBill] WHERE TypeInput IN ('OUT1','OUT2','OUT3') AND [PID] = '" + this.currPid + "' ORDER BY [CreateDate] DESC";
			SqlCommand selectCommand = new SqlCommand(cmdText, sqlConnection);
			SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(selectCommand);
			DataSet dataSet = new DataSet();
			sqlConnection.Open();
			sqlDataAdapter.Fill(dataSet);
			this.dgvBill.DataSource = dataSet.Tables[0];
			this.objDetailTable = dataSet.Tables[0];
			sqlConnection.Close();
			sqlConnection.Dispose();
			sqlDataAdapter.Dispose();
			dataSet.Dispose();
			if (this.dgvBill.Rows.Count > 0)
			{
				this.btnReport.Enabled = true;
				this.btnExportToExcel1.Enabled = true;
			}
			else
			{
				this.btnReport.Enabled = false;
				this.btnExportToExcel1.Enabled = false;
			}
			double num = 0.0;
			for (int i = 0; i < this.dgvBill.Rows.Count; i++)
			{
				num += double.Parse(this.dgvBill.Rows[i].Cells["MoneyAfterDiscount"].Value.ToString());
			}
			this.lblTotalDebt.Text = string.Format(Program.lenAffterDecimal, num + this.objPartner.getFistBalanceCustomer(this.currPid));
		}
		private void dgvProduct_CellClick(object sender, DataGridViewCellEventArgs e)
		{
			try
			{
				this.currPid = this.dgvProduct.Rows[e.RowIndex].Cells["CusID"].Value.ToString();
			}
			catch
			{
			}
		}
		private void dgvProduct_CellEnter(object sender, DataGridViewCellEventArgs e)
		{
			try
			{
				this.currPid = this.dgvProduct.Rows[e.RowIndex].Cells["CusID"].Value.ToString();
				this.lblObjectName.Text = this.dgvProduct.Rows[e.RowIndex].Cells["Column7"].Value.ToString();
				this.lblDebt.Text = this.dgvProduct.Rows[e.RowIndex].Cells["Column3"].Value.ToString();
				this.currAddress = this.dgvProduct.Rows[e.RowIndex].Cells["Column2"].Value.ToString();
				this.currPhone = this.dgvProduct.Rows[e.RowIndex].Cells["Column5"].Value.ToString();
				this.lblPayed.Text = string.Format(Program.lenAffterDecimal, this.objPartner.getTotalMoneyPayedCustomer(this.currPid));
				if (this.currPid != "")
				{
					this.getBillInput();
				}
			}
			catch
			{
			}
		}
		private void btnReport_Click(object sender, EventArgs e)
		{
			frmDebtNeedInDetailViewRep.objTable = this.objDetailTable;
			new frmDebtNeedInDetailView
			{
				providerName = this.lblObjectName.Text,
				providerAddress = this.currAddress,
				providerPhone = this.currPhone,
				AllDebt1 = this.lblTotalDebt.Text + " ",
				moneyPayed = this.lblPayed.Text + " ",
				AllDebt2 = this.lblDebt.Text + " "
			}.ShowDialog();
		}
		private void btnExportToExcel_Click(object sender, EventArgs e)
		{
			try
			{
				frmRepDebtNeedIn.objTable = new DataTable();
				frmRepDebtNeedIn.objTable = this.objTable;
				ActiveReport3 activeReport = new frmRepDebtNeedIn();
				activeReport.Run();
				XlsExport xlsExport = new XlsExport();
				SaveFileDialog saveFileDialog = new SaveFileDialog();
				saveFileDialog.ShowDialog();
				string text = saveFileDialog.FileName;
				if (text != "")
				{
					if (!text.ToUpper().Contains(".XLS"))
					{
						text += ".xls";
					}
					xlsExport.Export(activeReport.Document, text);
					MessageBox.Show("Hệ thống đã hoàn thành việc xuất dữ liệu ra file Excel", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
				}
				else
				{
					MessageBox.Show("Bạn chưa chọn đường dẫn và tên file cần xuất!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				}
			}
			catch
			{
			}
		}
		private void btnExportToExcel1_Click(object sender, EventArgs e)
		{
			try
			{
				frmDebtNeedInDetailViewRep.objTable = new DataTable();
				frmDebtNeedInDetailViewRep.objTable = this.objDetailTable;
				ActiveReport3 activeReport = new frmDebtNeedInDetailViewRep();
				activeReport.Run();
				XlsExport xlsExport = new XlsExport();
				SaveFileDialog saveFileDialog = new SaveFileDialog();
				saveFileDialog.ShowDialog();
				string text = saveFileDialog.FileName;
				if (text != "")
				{
					if (!text.ToUpper().Contains(".XLS"))
					{
						text += ".xls";
					}
					xlsExport.Export(activeReport.Document, text);
					MessageBox.Show("Hệ thống đã hoàn thành việc xuất dữ liệu ra file Excel", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
				}
				else
				{
					MessageBox.Show("Bạn chưa chọn đường dẫn và tên file cần xuất!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				}
			}
			catch
			{
			}
		}
	}
}
